<template>
    <n-scrollbar style="height: calc(100% - 58px);">
        <ul>
            <li class="list" v-for="index in count" :key="index">
                <div class="avatar">
                    <n-avatar round :size="60" fallback-src="https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg"
                        src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202003%2F26%2F20200326100605_SkLVh.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1702379201&t=449ae04a921579549f8ed208523c9a62" />
                </div>
                <div class="Bubble-chat-box">
                    <div class="triangle"></div>
                    <div class="chat">
                        <span> 每日一水 +10</span>
                    </div>
                </div>
            </li>
        </ul>
    </n-scrollbar>
    <div class="input">
        <el-form @keydown.enter="send">
            <el-form-item col="2">
                <el-autocomplete v-model="state" :fetch-suggestions="querySearchAsync" clearable placeholder="点击快捷回复"
                    style="width: calc(100% - 100px);margin: 0 10px;" @select="handleSelect" size="large" />
                <el-button type="primary" @click="send(count++)">发送</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup>
const count = ref(0)
const state = ref('')
const links = ref([])

const loadAll = () => {
    return [
        { value: '每日一水 +10' },
    ]
}

let timeout
const querySearchAsync = (queryString, cb) => {
    const results = queryString
        ? links.value.filter(createFilter(queryString))
        : links.value

    clearTimeout(timeout)
    timeout = setTimeout(() => {
        cb(results)
    }, 1000 * Math.random())
}
const createFilter = (queryString) => {
    return (restaurant) => {
        return (
            restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        )
    }
}

const handleSelect = () => {
    console.log();
}

onMounted(() => {
    links.value = loadAll()
})
</script>

<style scoped>
.list {
    float: left;
    width: 100%;
    margin: 8px 0;
    display: flex;
    align-items: center;
}

.avatar {
    float: left;
    display: flex;
}

.Bubble-chat-box {
    float: left;
    display: flex;
    width: calc(100% - 100px);
    margin: 5px 20px;
}

.triangle {
    float: left;
    position: relative;
    top: 5px;
    width: 0;
    height: 0;
    border-style: solid;
    border-color: transparent;
    border-width: 5px 5px 5px 0px;
    border-right-color: #fff;
}

.chat {
    float: left;
    padding: 15px;
    width: 100%;
    min-height: 35px;
    background-color: #fff;
    border-radius: 8px;
}

.input {
    width: 100%;
    height: 38px;
    margin-top: 20px;
}
</style>